package com.csdn.actuator;

import com.csdn.chain.*;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

@Component
public class HttpActuator extends AbstractActuator<HttpConfig> {
    @Override
    public void execute(EConfig<HttpConfig> config) {
        HttpConfig httpConfig = config.getConfig();
        HttpServletRequest request = httpConfig.getRequest();
        HttpServletResponse response = httpConfig.getResponse();
        TestContext testContext = new TestContext();
        InvokeResult invokeResult = BlockHelper.flow(testContext, () -> {
            List<Plugin> pluginList = new ArrayList<>();
            pluginList.add(new AuthorPlugin());
            pluginList.add(new RequestPlugin());
            pluginList.add(new CallPlugin());
            pluginList.add(new ResponsePlugin());
            Plugin.PluginChain chain = new Plugin.PluginChain(0, testContext, pluginList);
            return chain.proceed();
        });
        System.out.println(invokeResult.getData());
    }

    @Override
    public String getType() {
        return "HTTP";
    }
}
